package com.hzu.utils;

import javax.servlet.http.HttpServletRequest;

import com.hzu.bean.Worker;

public class MyBeanUtil {
	public static <T> Page<T> getPage(HttpServletRequest request, Class<T> clazz) {
		Page<T> page = new Page<T>();
		String sPage = request.getParameter("page");
		if (sPage != null && sPage.length() > 0) {
			page.setPage(Integer.parseInt(sPage));
		}
		return page;
	}
	/**
	 * 从请求中获取worker
	 * 
	 * @param request
	 * @return
	 */
	public static Worker getWorker(HttpServletRequest request) {
		Worker worker = new Worker();
		String name = request.getParameter("name");
		String number = request.getParameter("number");
		String department = request.getParameter("department");
		String role = request.getParameter("role");
		String workStatus = request.getParameter("workStatus");
		String entryDate = request.getParameter("entryDate");
		String leaveDate = request.getParameter("leaveDate");
		String idcard = request.getParameter("idcard");
		String validDate = request.getParameter("validDate");
		String gender = request.getParameter("gender");
		String birthday = request.getParameter("birthday");
		String nation = request.getParameter("nation");
		String marriage = request.getParameter("marriage");
		String education = request.getParameter("education");
		String major = request.getParameter("major");
		String graduation = request.getParameter("graduation");
		String contract = request.getParameter("contract");
		String conValidDate = request.getParameter("conValidDate");
		String conInvalidDate = request.getParameter("conInvalidDate");
		String telephone = request.getParameter("telephone");
		String address = request.getParameter("address");
		String linkMan = request.getParameter("linkMan");
		String linkTel = request.getParameter("linkTel");
		String workerId = request.getParameter("workerId");
		worker.setAddress(address);
		worker.setBirthday(DateUtils.getDate(birthday));
		worker.setConInvalidDate(DateUtils.getDate(conInvalidDate));
		worker.setContract(contract);
		worker.setConValidDate(DateUtils.getDate(conValidDate));
		worker.setDepartment(department);
		worker.setEducation(education);
		worker.setEntryDate(DateUtils.getDate(entryDate));
		worker.setGender(gender);
		worker.setGraduation(graduation);
		worker.setIdcard(idcard);
		worker.setLeaveDate(DateUtils.getDate(leaveDate));
		worker.setLinkMan(linkMan);
		worker.setLinkTel(linkTel);
		worker.setMajor(major);
		worker.setMarriage(marriage);
		worker.setName(name);
		worker.setNation(nation);
		worker.setNumber(number);
		worker.setRole(role);
		worker.setTelephone(telephone);
		worker.setValidDate(DateUtils.getDate(validDate));
		worker.setWorkerId(workerId == null ? null : Integer.parseInt(workerId));
		worker.setWorkStatus(workStatus);
		return worker;
	}
}
